<template>
  <div class="pager-select" :class="'pager_select_'+size">
    <input
      ref="input"
      class="el-input__inner"
      :value="value"
      v-bind="$attrs"
      :class="'pager_select_'+size"
      type="text"
      autocomplete="off"
      :placeholder="placeholder"
      readonly
      @input="$emit('change', $event.target.value)"
      @focus="handleFocus"
    >
    <span class="el-input__suffix">
      <span class="el-input__suffix-inner">
        <i class="custom-i" :class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]" />
      </span>
    </span>
    <div class="custom-select-tag" />
    <div v-if="isShow">
      <div class="custom-popper__arrow" />
      <div ref="show" class="custom-tag-body" style="overflow: hidden">
        <div class="scroll-body">
          <el-table
            ref="multipleTable"
            :data="dataList"
            style="width: 100%"
            height="220"
          >
            <el-table-column
              type="selection"
              width="55"
              :selectable="customSelectTable"
            />
            <el-table-column prop="name" label="标题" />
            <el-table-column>
              <template slot="header" slot-scope="scope">
                <el-input
                  v-model="query.blurry"
                  size="mini"
                  placeholder="请输入查询的内容"
                >
                  <i slot="suffix" class="el-input__icon el-icon-search" @click="doQuery(scope.row)" />
                </el-input>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            :current-page="query.page"
            :page-size="query.size"
            :total="pagerSize"
            style="margin-top: 8px;"
            layout="total, prev, pager, next, sizes"
            :page-sizes="[5, 10, 15, 20]"
            @current-change="pagerHandleCurrentChange"
            @size-change="pagerHandleSizeChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CustomPageIndex',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    value: [String, Number],
    size: {
      type: String,
      default: 'small'
    },
    placeholder: String,
    clearable: {
      type: Boolean,
      default: false
    },
    defaultOptions: {

    }
  },
  data() {
    return {
      visible: false,
      isShow: false,
      pagerSize: 0,
      dataList: [
        { id: 1, name: '新增项目' },
        { id: 2, name: '新增项目' },
        { id: 3, name: '新增项目' },
        { id: 4, name: '新增项目' },
        { id: 5, name: '新增项目' },
        { id: 6, name: '新增项目' },
        { id: 7, name: '新增项目' }
      ],
      query: {
        blurry: '',
        page: 1,
        size: 5
      },
      options: {
        method: 'get',
        url: '',
        value: 'id',
        params: {
          blurry: '',
          page: 1,
          size: 5
        }
      }
    }
  },
  computed: {
    iconClass() {
      return this.visible === true ? 'arrow-up is-reverse' : 'arrow-down'
    }
  },
  created() {
    document.addEventListener('click', e => {
      const input = this.$refs.input
      const show = this.$refs.show
      if ((undefined !== input && undefined !== show) && (show.contains(e.target) || input.contains(e.target))) {
        this.visible = true
        this.isShow = true
      } else {
        this.visible = false
        this.isShow = false
      }
    })
  },
  methods: {
    handleFocus() {
      this.visible = true
      this.isShow = true
    },
    doQuery(object) {},
    initData() {},
    pagerHandleCurrentChange(val) {
      this.query.page = val
      this.initData()
    },
    pagerHandleSizeChange(val) {
      this.query.size = val
      this.initData()
    },
    customSelectTable(row) {}
  }
}
</script>

<style scoped>
.pager-select {
  width: 100%;
  cursor: pointer;
  position: relative;
}
.el-input__inner {
  outline: none;
  border: 1px solid #dcdfe6;
  transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  border-radius: 4px;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  padding: 0px 15px;
  box-sizing: border-box;
}
.pager_select_suffix {
  height: 40px;
  line-height: 40px;
  font-size: inherit;
}
.pager_select_medium {
  height: 36px;
  line-height: 36px;
  font-size: inherit;
}
.pager_select_small {
  height: 32px;
  line-height: 32px;
  font-size: inherit;
}
.pager_select_mini {
  height: 28px;
  line-height: 28px;
  font-size: inherit;
}
.el-input__inner:focus {
  outline: none;
  border-color: #409eff;
}
.pager_select_suffix .custom-i {
  line-height: 40px;
}
.pager_select_medium .custom-i {
  line-height: 36px;
}
.pager_select_small .custom-i {
  line-height: 32px;
}
.pager_select_mini .custom-i {
  line-height: 28px;
}
.custom-i {
  color: #c0c4cc;
  font-size: 14px;
  transition: transform .3s;
  transform: rotate(180deg);
  cursor: pointer;
}
.custom-tag-body {
  position: absolute;
  z-index: 9998;
  left: 0px;
  right: 0px;
  height: 280px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  padding: 10px 15px;
  box-sizing: border-box;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  margin-top: 8px;
}
.custom-popper__arrow{
  position: absolute;
  z-index: 9999;
  height: 10px;
  width: 10px;
  left: 35px;
  background-color: #ffffff;
  transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  -o-transform:  rotate(45deg);
  margin-top: 4px;
  border-radius: 1px;
  border-left: 1px solid #dcdfe6;
  border-top: 1px solid #dcdfe6;
}
</style>
